package com.jie.deletefile.design;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TextInputLayout;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.jie.deletefile.R;

public class EditActivity extends AppCompatActivity implements View.OnClickListener {

    private Button e_btn;
    private EditText et;
    private TextInputLayout tl;
    private Button e_btn2;
    private Button e_btn3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit);
        initView();
    }

    private void initView() {
        e_btn = (Button) findViewById(R.id.e_btn);

        e_btn.setOnClickListener(this);
        et = (EditText) findViewById(R.id.et);
        et.setOnClickListener(this);
        tl = (TextInputLayout) findViewById(R.id.tl);
        tl.setOnClickListener(this);
        et.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (s.length() < 6) {
                    tl.setErrorEnabled(true);
                    tl.setError("不能少于6位");
                } else {
                    tl.setErrorEnabled(false);
                }

            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        e_btn2 = (Button) findViewById(R.id.e_btn2);
        e_btn2.setOnClickListener(this);
        e_btn3 = (Button) findViewById(R.id.e_btn3);
        e_btn3.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.e_btn:
                Intent intent = new Intent(EditActivity.this, AutocompleteActivity.class);
                startActivity(intent);

                break;
            case R.id.e_btn2:
                Intent intent1 = new Intent(EditActivity.this, ToolbarActivity.class);
                startActivity(intent1);
                break;
            case R.id.e_btn3:
                Intent intent2 = new Intent(EditActivity.this, CollToolBarActivity.class);
                startActivity(intent2);
                break;
        }
    }

}
